﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Vision.Common.Common
{
    static class BitmapEx
    {
        public static void CopyFrom(this Bitmap dstImg,Point org,Bitmap srcImg,Point Loc,float angle)
        {
            Graphics g = Graphics.FromImage(dstImg);
            g.TranslateTransform(Loc.X-org.X, Loc.Y-org.Y);
            g.RotateTransform(angle);
            g.DrawImage(srcImg,0,0, srcImg.Width,srcImg.Height);
        }
        /// <summary>
        /// 从文件加载图像，避免文件占用
        /// </summary>
        /// <param name="fileName">文件名称</param>
        /// <returns></returns>
        public static Bitmap LoadFromFile(/*this Bitmap bitmap,*/string fileName)
        {
            Bitmap bmp = null;
            try
            {
                var fileStream = new FileStream(fileName, FileMode.Open, FileAccess.Read);
                bmp = new Bitmap(fileStream);
                fileStream.Close();
                fileStream.Dispose();
            }
            catch (Exception ex)
            {
                //Log.Instance.Error($"加载图片失败,路径:{fileName},{ex.Message}");
            }
            return bmp;
        }
    }
}
